package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.BoardQuery;
import com.xingkeduo.pojo.table.BoardTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.tool.CommonUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class BoardService {
    private static final String NAMESPACE = BoardTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<BoardTable, BoardQuery> dao;

    public BoardTable selectById(long id) throws Throwable {
        BoardTable boardTable = dao.select(NAMESPACE, id);
        if (!CommonUtil.isEmpty(boardTable))
            return boardTable;
        return null;
    }

    public BoardTable selectByCode(long code) throws Throwable {
        BoardTable boardTable = dao.select(NAMESPACE, code);
        if (!CommonUtil.isEmpty(boardTable))
            return boardTable;
        return null;
    }

    public Page<BoardTable> selectLists(BoardQuery boardQuery,Integer pageNum,Integer pageSize) throws Throwable {
        Page<BoardTable> boardTablePage = dao.pageSelect(NAMESPACE,boardQuery,pageNum,pageSize);
        return boardTablePage;
    }

    //插入
    public int insert(BoardTable boardTable) throws Throwable {
        return dao.insert(NAMESPACE, boardTable);
    }

    //更新
    public int update(BoardTable boardTable) throws Throwable {
        return dao.update(NAMESPACE, boardTable);
    }

    //删除
    public int delete(BoardTable boardTable) throws Throwable {
        return dao.update(NAMESPACE, boardTable);
    }
}
